package vn.mobiistar.videoapp.other;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import vn.mobiistar.videoapp.util.GlobalApplication;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
/*
 * @NamNguyenGiang
 */
public class ImageLoad {
	public static void  display(String Uri,ImageView img){
		ImageLoader.getInstance().displayImage(Uri, img, GlobalApplication.options, new AnimateFirstDisplayListener());
	}
	
	private static class AnimateFirstDisplayListener extends SimpleImageLoadingListener {

		static final List<String> displayedImages = Collections.synchronizedList(new LinkedList<String>());

		@Override
		public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
			if (loadedImage != null) {
				ImageView imageView = (ImageView) view;
				boolean firstDisplay = !displayedImages.contains(imageUri);
				if (firstDisplay) {
					FadeInBitmapDisplayer.animate(imageView, 500);
					displayedImages.add(imageUri);
				}
			}
		}
	}
}
